#include "mixchunk.h"
#include "audiomanager.h"

using std::string;
using namespace EPOC;

MixChunk::MixChunk()
{
	SetClassID(kCLASSID_MIXCHUNK);
	m_pAudioManager = NULL;
	m_pSDLMixChunk = NULL;
	m_sFilePath = "";
}

MixChunk::MixChunk(AudioManager *pAudioManager)
{
	SetClassID(kCLASSID_MIXCHUNK);
	m_pAudioManager = pAudioManager;
	m_pSDLMixChunk = NULL;
	m_sFilePath = "";
}

MixChunk::~MixChunk()
{
	MixChunk::Cleanup();
}

void MixChunk::Cleanup()
{
	if(m_pAudioManager)
		m_pAudioManager->RemoveLoadedMixChunk(this);

	if(m_pSDLMixChunk)
		Mix_FreeChunk(m_pSDLMixChunk);
	
	m_pSDLMixChunk = NULL;
	m_sFilePath = "";
}

bool MixChunk::Initialize(string sFilePath, Mix_Chunk *pSDLMixChunk)
{
	if(m_pSDLMixChunk)
		return false;

	if(!pSDLMixChunk)
		return false;

	m_sFilePath = sFilePath;
	m_pSDLMixChunk = pSDLMixChunk;

	return true;
}